package com.share.simple.model;

import lombok.Data;
import org.springframework.http.HttpStatus;

/**
 * @author:caifan
 * @since 2023/7/12
 */
@Data
public class ResultBean<T> {

    private Integer code;

    private String message;

    public ResultBean(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    private T data;

    public ResultBean(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static ResultBean success() {
        return new ResultBean(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase());
    }

    public static <T> ResultBean<T> success(T data) {
        return new ResultBean<T>(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), data);
    }

    public static ResultBean fail(Integer code, String message) {
        return new ResultBean(code, message);
    }
}
